RAIS  3.2
C:/Projekte/RAIS/dataaccesslayertest/CommonClasses/TranslationItemTest.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Data.SqlClient;
00004 using System.Text;
00005 using NUnit.Framework;
00006 using RAIS.Common.Localization;
00007 using RAIS.DataAccessLayer;
00008 using TranslationItems = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.TranslationItem>;
00009 
00010 namespace RAIS.DataAccessLayerTest.CommonClasses
00011 {
00012         [TestFixture]
00013         public class TranslationItemTest
00014         {
00015                 string expectedContext = "Context 1";
00016                 int expectedSourceLanguageLCID = 9;
00017                 string expectedSourceLanguageName = "English";
00018                 string expectedTestTranslation = "Test Translation";
00019                 string expectedTranslationResult = "Expected Translation Result";
00020                 int expectedTargetLanguageLCID = 1;
00021                 string expectedTargetLanguageName = "Arabic";
00022 
00023                 private TranslationItem translationItem;
00024 
00025                 [SetUp]
00026                 public void Init()
00027                 {
00028                         /*// Clear DB
00029                         Assert.IsTrue(TestUtilities.TruncateTable("Translation"), "Clear [Translation] table before test error");
00030                         Assert.IsTrue(TestUtilities.TruncateTable("Context"), "Clear [Translation] table before test error");
00031                         Assert.IsTrue(TestUtilities.DeleteTestCultures(), "Delete cultures before test error");
00032 
00033                         // Preparations
00034                         string errorMessage = "";
00035                         Culture sourceLanguage = Localisation.SupportedLanguages[this.expectedSourceLanguageName];
00036                         Culture targetLanguage = TestUtilities.NewTestCultureWithSave(1);
00037                         //Add new culture
00038                         try
00039                         {
00040                                 Localisation.Translate(expectedContext, expectedTestTranslation, sourceLanguage.Name, targetLanguage.Name);
00041 
00042                         }
00043                         catch
00044                         {
00045                         }
00046                         Context culture = Localisation.Contexts[expectedContext];
00047                         TranslationItems translationItems = Localisation.GetTranslationsByContext(culture, sourceLanguage, targetLanguage, true);
00048                         translationItems[expectedContext + " " + expectedTestTranslation].TargetText = expectedTranslationResult;
00049                         Assert.IsTrue(Localisation.SaveTranslations(translationItems, ref errorMessage), "Preparation for test - save translation error");
00050 
00051                         translationItem = translationItems[expectedContext + " " + expectedTestTranslation];
00052                         //translationItem = new TranslationItem();
00053                         //translationItem.ID = this.expectedID;*/
00054                 }
00055 
00056                 [Test]
00057                 public void GetName()
00058                 {
00059                         // Test 
00060                         Assert.AreEqual(this.expectedContext + " " + expectedTestTranslation
00061                                 , this.translationItem.Name);
00062                 }
00063                 [Test]
00064                 public void GetContext()
00065                 {
00066                         // Test 
00067                         Assert.AreEqual(this.expectedContext, this.translationItem.Context.Name);
00068                 }
00069                 [Test]
00070                 public void GetSourceLanguage()
00071                 {
00072                         // Test 
00073                         Assert.AreEqual(this.expectedSourceLanguageLCID, this.translationItem.SourceLanguage.LCID);
00074                         Assert.AreEqual(this.expectedSourceLanguageName, this.translationItem.SourceLanguage.Name);
00075                 }
00076                 [Test]
00077                 public void GetTargetLanguage()
00078                 {
00079                         // Test 
00080                         Assert.AreEqual(this.expectedTargetLanguageLCID, this.translationItem.TargetLanguage.LCID);
00081                         Assert.AreEqual(this.expectedTargetLanguageName, this.translationItem.TargetLanguage.EnglishName);
00082                 }
00083                 [Test]
00084                 public void GetSourceText()
00085                 {
00086                         // Test 
00087                         Assert.AreEqual(this.expectedTestTranslation, this.translationItem.SourceText);
00088                 }
00089                 [Test]
00090                 public void GetTargetText()
00091                 {
00092                         // Test 
00093                         Assert.AreEqual(this.expectedTranslationResult, this.translationItem.TargetText);
00094                 }
00095                 [Test]
00096                 public void GetModified()
00097                 {
00098                         // Test 
00099                         Assert.IsFalse(this.translationItem.Modified);
00100                 }
00101                 [Test]
00102                 public void GetModified_AfterResultTheSame()
00103                 {
00104                         // Preparation
00105                         this.translationItem.TargetText = expectedTranslationResult;
00106 
00107                         // Test 
00108                         Assert.IsFalse(this.translationItem.Modified);
00109                 }
00110                 [Test]
00111                 public void GetModified_AfterResultChanged()
00112                 {
00113                         // Preparation
00114                         this.translationItem.TargetText = "New Translation";
00115 
00116                         // Test 
00117                         Assert.IsTrue(this.translationItem.Modified);
00118                 }
00119                 [Test]
00120                 public void GetModified_AfterResultChangedAndThenSetSame()
00121                 {
00122                         // Preparation
00123                         this.translationItem.TargetText = "New Translation";
00124                         this.translationItem.TargetText = "New Translation";
00125 
00126                         // Test 
00127                         Assert.IsTrue(this.translationItem.Modified);
00128                 }
00129                 [Test]
00130                 public void SetTargetText()
00131                 {
00132                         // Preparation
00133                         string expectedNewTargetText = "New Translation";
00134 
00135                         // Test 
00136                         this.translationItem.TargetText = expectedNewTargetText;
00137 
00138                         // Check
00139                         Assert.AreEqual(expectedNewTargetText, this.translationItem.TargetText);
00140                 }
00141 
00142                 [TearDown]
00143                 public void Finally()
00144                 {
00145                         // Restore to previous state
00146                         Assert.IsTrue(TestUtilities.TruncateTable("Translation"), "Clear [Translation] table after test error");
00147                         Assert.IsTrue(TestUtilities.TruncateTable("Context"), "Clear [Translation] table after test error");
00148                         Assert.IsTrue(TestUtilities.DeleteTestCultures(), "Delete cultures after test error");
00149                 }
00150         }
00151 }